<template>
	<view>
		<!-- 商品详情的图片轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in swipers" :key='index'>
				<image src="../../static/phone/phone2.png" mode=""></image>
			</swiper-item>
		</swiper>
		<view class="box1">
			<view class="price">
				<text>￥{{info.sell_price}}</text>
				<text>￥{{info.market_price}}</text>
			</view>
			<view class="goods_name">{{info.title}}</view>
		</view>
		<view class="box2">
			<view>货号：{{info.goods_no}}</view>
			<view>库存：{{info.stock_quantity}}</view>
		</view>
		<view class="box3">
			<view class="tit">详情介绍</view>
			<view class="content">
				<rich-text :nodes="goodsContent"></rich-text>
			</view>
		</view>
		<view class="goods_nav">
			<uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
		</view>
	</view>
</template>

<script>
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue'
	export default {
		data() {
			return {
				id:0,
				swipers:[],
				info:[],
				goodsContent:"",
				options: [
					{
						icon: 'headphones',
						text: '客服'
					}, 
					{
						icon: 'shop',
						text: '店铺',
						info: 2,
						infoBackgroundColor:'#007aff',
						infoColor:"red"
					},
					{
						icon: 'cart',
						text: '购物车',
						info: 2
					}],
				buttonGroup: [
					{
					  text: '加入购物车',
					  backgroundColor: '#ff0000',
					  color: '#fff'
					},
					{
					  text: '立即购买',
					  backgroundColor: '#ffa200',
					  color: '#fff'
					}]
			}
		},
		methods: {
			async getSwipersData(){
				const res = await this.$myRequest({
					url:'/api/getthumimages/'+ this.id
				})
				this.swipers = res.data.message
			},
			async getDetailInfo(){
				const res = await this.$myRequest({
					url:'/api/goods/getinfo/'+ this.id
				})
				this.info = res.data.message[0]
			},
			async getDetailContent () {
				const res = await this.$myRequest({
					url: '/api/goods/getdesc/'+this.id
				})
				this.goodsContent = res.data.message[0].content			
			},
			onClick (e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick (e) {
			    console.log(e)
				if(e.index === 0) this.options[2].info++
			}
		},
		onLoad(Option) {
			this.id = Option.id
			this.getSwipersData()
			this.getDetailInfo()
			this.getDetailContent()
		},
		components: {uniGoodsNav}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		width: 100%;
		background:#e6e6e6;
		swiper{
			height: 680rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.box1{
			border-top: 1rpx solid #999999;
			padding: 10px;
			background: #ffffff;
			.price {
				font-size: 35rpx;
				color: #b50e03;
				line-height: 80rpx;
				text:nth-child(2){
					color: #ccc;
					font-size: 28rpx;
					text-decoration: line-through;
					margin-left: 20rpx;
				}
			}
			.goods_name{
				font-size: 30rpx;
				line-height: 60rpx;
			}
		}
		.box2 {
			background: #ffffff;
			padding: 0 10px;
			font-size: 30rpx;
			line-height: 70rpx;
			margin: 10rpx 0;
		}
		.box3 {
			padding-bottom: 50px;
			background: #ffffff;
			.tit{
				font-size: 30rpx;
				padding-left: 10px;
				border-bottom: 1px solid #eee;
				line-height: 70rpx;
			}
			.content {
				padding: 10px;
				font-size: 28rpx;
				color: #333;
				line-height: 50rpx;
			}
		}
		.goods_nav {
			position: fixed;
			bottom:0;
			width: 100%;
		}
		
	}
</style>
